package com.three.controller;

import com.baor.baseUtil.R;
import com.three.domain.Students;
import com.three.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping(value = "/updateStudentByStudent")
    public R updateStudent(@RequestBody Students students){
        return studentService.updateStudent(students);
    }





    //查询在习生列表
    @RequestMapping(value = "/studentslist")
    public R studentsList(@RequestBody Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        Integer xiaoshou_id = (Integer) map.get("xiaoshou_id");
        return studentService.studentsList(pageIndex, pageSize, xiaoshou_id);
    }
    //添加在习生
    @RequestMapping(value = "/addstu")
    public R addstudent(@RequestBody Map<String,Object> map) {
        return studentService.addstu(map);
    }
    // 更新学生信息
    @RequestMapping("/updatestu")
    public R updateStudents(@RequestBody Students student) {

        return studentService.updateStudents(student);
    }

    // 软删除学生
    @RequestMapping("/deletestu")
    public R softDeleteStudent(@RequestBody Map<String, Integer> requestBody) {
        int student_id = requestBody.get("student_id");
        int user_id = requestBody.get("user_id");
        int row = studentService.softDeleteStudent(student_id,user_id);
        if(row>0){
            return R.ok();
        }
        return R.er();
    }

    @RequestMapping("/searchstu")
    public R searchStudents(@RequestBody Map<String, Object> map) {
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        String name = (String) map.get("keyword");
        Integer xiaoshou_id = (Integer) map.get("xiaoshou_id");
        return studentService.findStudentByname(pageIndex,pageSize,name,xiaoshou_id);
    }
    //销售下拉框
    @RequestMapping("/xiaoshouList")
    public R xiaoshouList() {
        return studentService.xiaoshouList();
    }

    // 添加未报到学生
    @RequestMapping("/addstu_no_sign")
    public R addstu_no_sign(@RequestBody Map<String,Object> map) {
        return studentService.addstu_no_sign(map);
    }
    // 查询未报到学生
    @RequestMapping("/getstu_no_sign")
    public R getstu_no_sign(@RequestBody Map<String, Object> map) {
        Integer pageIndex = (Integer) map.get("pageIndex");
        Integer pageSize = (Integer) map.get("pageSize");
        String keyword = (String) map.get("keyword");
        String start_date = (String) map.get("start_date");
        String end_date = (String) map.get("end_date");
        Integer xiaoshou_id = (Integer) map.get("xiaoshou_id");
        return studentService.getstu_no_sign(pageIndex,pageSize,keyword,start_date,end_date,xiaoshou_id);
    }
    //批量删除未报到学生
    @RequestMapping("/delete_no_sign")
    public R delete_no_sign(@RequestBody List<Integer> student_id) {
        return studentService.delete_no_sign(student_id);
    }
    //批量转移未报到学生
    @RequestMapping("/update_no_sign")
    public R update_no_sign(@RequestBody List<Integer> student_id, @RequestBody Integer xiaoshou_id) {
        return studentService.update_no_sign(student_id,xiaoshou_id);
    }
    //批量转为预招生
    @RequestMapping("/update_no_sign_to_pre")
    public R updateStatus(@RequestBody List<Students> students) {
        return studentService.updateStatus(students);
    }
    @RequestMapping("/sale_statistics")
    public R sale_statistics(@RequestBody Map<String, Object> map) {
        return studentService.sale_statistics(map);
    }
    //销售统计下的详情
    @RequestMapping("/sale_statistics_by_xiaoshou")
    public R sale_statistics_by_xiaoshou(@RequestBody Map<String, Object> map) {
        return studentService.sale_statistics_by_xiaoshou(map);
    }
}
